﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.EShop.Common.Entity;
using Runda.EShop.Bll;
using Runda.EShop.Common.Utility;

namespace Runda.EShop.SaaS.UserControl
{
    public partial class EnterpriseInfo : UserControlBase
    {
        private BizEnterpriseEntity _entity;
        public BizEnterpriseEntity entity
        {
            set { _entity = value; }
            get {
                if (_entity == null)
                {
                    _entity = new BizEnterpriseBll().Get<BizEnterpriseEntity>(EntID);
                }
                return _entity;
            }
        }

        public Guid EntID
        {
            get
            {
                return new Guid(base.Page.Request.QueryString["EntID"]);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ltlEntCode.Text = entity.EntCode;
                ltlEntName.Text = entity.EntName;
                if (entity.ApparatusLicenseDeadline != DateTime.MinValue)
                {
                    ltlApparatusLicenseDeadline.Text = entity.ApparatusLicenseDeadline.ToString("yyyy-MM-dd");
                }
                if (entity.BusinessLicenseDeadline != DateTime.MinValue)
                {
                    ltlBusinessLicenseDeadline.Text = entity.BusinessLicenseDeadline.ToString("yyyy-MM-dd");
                }
                if (entity.DrugLicenseDeadline != DateTime.MinValue)
                {
                    ltlDrugLicenseDeadline.Text = entity.DrugLicenseDeadline.ToString("yyyy-MM-dd");
                }
                ltlExpired.Text = entity.Expired.ToString();
                txtBussinessScope.Text = entity.BusinessScope;

                EnumHelper.EnterpriseType type =  (EnumHelper.EnterpriseType)entity.EntType;
                ltlEntType.Text = EnumDescAttribute.GetFieldText(type);
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            this.Load +=new EventHandler(Page_Load);
        }
    }
}